﻿using System;
using System.Collections.Generic;
using System.Linq;
using SimpleVelocity;

/// <summary>
/// This is a basic view object. When on professional app you will have view more elaborate.
/// </summary>
public class PersonView : ViewBase
{
    public string PersonName { private set; get; }

    public PersonView(string name)
        : base("PersonView.vm")
    {
        this.PersonName = name; // External parameter
    }

    protected override void SetDataContext()
    {
        base.Add("this", this); // this = ALIAS
    }

    #region Methods

    public Person GetPersonFound()
    {
        Person obj = this.GetListPerson().Find(p => p.Name == this.PersonName);
        return obj == null ? new Person("-", -1) : obj;
    }
    
    private List<Person> GetListPerson()
    {
        return new List<Person>()
        {
            new Person("Alfred", 20),
            new Person("Lain", 35),
            new Person("Leco", 25),
            new Person("Bilbo", 50)
        };
    }

#endregion
}
